#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    int a = 0, b = 1;
    while (1)
    {
        int c = a + b;
        a = b;
        b = c;
        if (a <= n && n <= b)
            break;
    }
    cout << min(n - a, b - n) << endl;
    return 0;
}